package com.tencent.backstage.service.impl;

import com.tencent.backstage.dao.AdminRepository;
import com.tencent.backstage.dao.UserInfoDao;
import com.tencent.backstage.entity.Admin;
import com.tencent.backstage.entity.UserInfo;
import com.tencent.backstage.enums.ResultEnum;
import com.tencent.backstage.service.AdminService;
import com.tencent.backstage.utils.ResultVOUtil;
import com.tencent.backstage.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AdminServiceImpl implements AdminService{
    @Autowired
    private AdminRepository adminRepository;
    @Autowired
    private UserInfoDao userInfoDao;
    @Override
    public ResultVO getAllUser() {
        List<UserInfo> list =  userInfoDao.findAll();
        return  ResultVOUtil.success(list);
    }
    @Override
    public ResultVO login(String username, String password) {
        Admin admin =  adminRepository.findByUserNameAndPassword(username,password);
        if(admin!=null){
            return ResultVOUtil.success(admin.getUserName());
        }else{
            return ResultVOUtil.error(ResultEnum.LOGIN_ERROR.getCode(),ResultEnum.LOGIN_ERROR.getMessage());
        }
    }
}
